home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1996 June
/
MACPOWER-1996-06.ISO.7z
/
MACPOWER-1996-06.ISO
/
AMUG
/
PROGRAMING_7
/
AntiAliasMan 2.0
/
AntiAliasMan
/
AntiAliasManTester.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-01
|
6KB
|
282 lines
#include "AntiAliasMan.h"
void ToolBoxInit(void);
void MenuBarInit(void);
void WindowInit(void);
void EventLoop(void);
void DoEvent(EventRecord *eventPtr);
void HandleMouseDown(EventRecord *eventPtr);
void HandleMenuChoice(long menuChoice);
void DoUpdate(WindowPtr window);
WindowPtr gWind;
void main(void)
{
ToolBoxInit();
MenuBarInit();
WindowInit();
AntiAliasManInit();
EventLoop();
}
void ToolBoxInit(void)
{
InitGraf(&qd.thePort);
InitWindows();
InitFonts();
InitMenus();
TEInit();
InitDialogs(nil);
InitCursor();
}
void MenuBarInit(void)
{
Handle menuBar;
MenuHandle menu;
menuBar=GetNewMBar(128);
SetMenuBar(menuBar);
menu=GetMHandle(128);
AddResMenu(menu,'DRVR');
DisableItem(menu,1);
DrawMenuBar();
}
void WindowInit(void)
{
Rect place;
SetRect(&place,0,20,640,480);
gWind=NewCWindow(nil,&place,"¥p",true,4,(WindowPtr)-1L,true,0L);
}
void EventLoop(void)
{
EventRecord event;
while(1)
{
while(!WaitNextEvent(everyEvent,&event,10L,nil));
DoEvent(&event);
}
}
void DoEvent(EventRecord *eventPtr)
{
char theChar;
WindowPtr window;
switch(eventPtr->what)
{
case mouseDown:
HandleMouseDown(eventPtr);
break;
case keyDown:
case autoKey:
theChar=eventPtr->message &charCodeMask;
if(eventPtr->modifiers &cmdKey) HandleMenuChoice(MenuKey(theChar));
break;
case updateEvt:
window=(WindowPtr)eventPtr->message;
DoUpdate(window);
break;
}
}
void HandleMouseDown(EventRecord *eventPtr)
{
WindowPtr whichWindow;
short thePart;
long menuChoice;
Point thePt;
thePart=FindWindow(eventPtr->where,&whichWindow);
switch(thePart)
{
case inMenuBar:
menuChoice=MenuSelect(eventPtr->where);
HandleMenuChoice(menuChoice);
HiliteMenu(false);
break;
case inSysWindow:
SystemClick(eventPtr,whichWindow);
break;
case inContent:
SetPort(whichWindow);
SelectWindow(whichWindow);
thePt=eventPtr->where;
GlobalToLocal(&thePt);
break;
}
}
void HandleMenuChoice(long menuChoice)
{
short menu,item;
Str255 dAName;
MenuHandle appleMenu;
GrafPtr savePort;
menu=HiWord(menuChoice);
item=LoWord(menuChoice);
switch(menu)
{
case 128:
if(item==1);
else
{
appleMenu=GetMHandle(128);
GetPort(&savePort);
GetItem(appleMenu,item,dAName);
OpenDeskAcc(dAName);
SetPort(savePort);
}
break;
case 129:
if(item==1)
{
CloseWindow(FrontWindow());
if(FrontWindow()==nil)
{
appleMenu=GetMHandle(129);
DisableItem(appleMenu,1);
}
}
if(item==2) ExitToShell();
break;
case 130:
break;
}
}
void DoUpdate(WindowPtr window)
{
Rect place;
short i;
OSErr err;
long time;
Str255 timestr;
BeginUpdate(window);
SetPort(window);
if(window==gWind)
{
time = TickCount();
ForeColor(blackColor);
MoveTo(10,40);
TextFont(20);
TextSize(12);
err = DrawAAString( "¥pAntialiased" );
TextSize(48);
err = DrawAAString( "¥p Text." );
MoveTo(10,80);
TextSize(12);
DrawString( "¥pQuickdraw" );
TextSize(48);
DrawString( "¥p Text." );
SetRect(&place,20,200,100,280);
BackColor(redColor);
ForeColor(blueColor);
err = EraseAARoundRect(&place,20,20);
OffsetRect(&place,81,0);
EraseRoundRect(&place,20,20);
OffsetRect(&place,81,0);
err = PaintAAOval(&place);
OffsetRect(&place,81,0);
PaintOval(&place);
OffsetRect(&place,81,0);
err = InvertAAArc(&place,180,45);
OffsetRect(&place,81,0);
InvertArc(&place,180,45);
SetRect(&place,14,290,587,355);
err = InvertAARoundRect(&place,20,20);
SetRect(&place,15,300,40,345);
for(i=0;i<22;i++)
{
err = InvertAAOval(&place);
OffsetRect(&place,26,0);
}
MoveTo(20,300);
err = AALineTo(120,320);
err = AALineTo(20,310);
err = AALineTo(580,310);
err = AALineTo(400,345);
err = AALineTo(300,320);
SetRect(&place,14,390,587,455);
InvertRoundRect(&place,20,20);
SetRect(&place,15,400,40,445);
for(i=0;i<22;i++)
{
InvertOval(&place);
OffsetRect(&place,26,0);
}
MoveTo(20,400);
LineTo(120,420);
LineTo(20,410);
LineTo(580,410);
LineTo(400,445);
LineTo(300,420);
SetRect(&place,200,20,250,70);
err = FrameAARoundRect(&place,20,20);
OffsetRect(&place,51,0);
err = PaintAARoundRect(&place,20,20);
OffsetRect(&place,51,0);
err = EraseAARoundRect(&place,20,20);
OffsetRect(&place,51,0);
err = InvertAARoundRect(&place,20,20);
OffsetRect(&place,51,0);
err = FillAARoundRect(&place,20,20,0L);
SetRect(&place,200,71,250,121);
FrameRoundRect(&place,20,20);
OffsetRect(&place,51,0);
PaintRoundRect(&place,20,20);
OffsetRect(&place,51,0);
EraseRoundRect(&place,20,20);
OffsetRect(&place,51,0);
InvertRoundRect(&place,20,20);
OffsetRect(&place,51,0);
FillRoundRect(&place,20,20,0L);
TextSize(15);
ForeColor( greenColor );
MoveTo(225-StringWidth("¥pFrame")/2,15);
err = DrawAAString("¥pFrame");
MoveTo(276-StringWidth("¥pPaint")/2,15);
err = DrawAAString("¥pPaint");
MoveTo(327-StringWidth("¥pErase")/2,15);
err = DrawAAString("¥pErase");
MoveTo(378-StringWidth("¥pInvert")/2,15);
err = DrawAAString("¥pInvert");
MoveTo(429-StringWidth("¥pFill")/2,15);
err = DrawAAString("¥pFill");
MoveTo(225-StringWidth("¥pFrame")/2,135);
DrawString("¥pFrame");
MoveTo(276-StringWidth("¥pPaint")/2,135);
DrawString("¥pPaint");
MoveTo(327-StringWidth("¥pErase")/2,135);
DrawString("¥pErase");
MoveTo(378-StringWidth("¥pInvert")/2,135);
DrawString("¥pInvert");
MoveTo(429-StringWidth("¥pFill")/2,135);
DrawString("¥pFill");
NumToString( TickCount() - time, timestr );
ForeColor( blackColor );
MoveTo( 20, 190 );
TextSize( 14 );
DrawAAString( "¥pTotal time: " );
DrawAAString( timestr );
DrawAAString( "¥p 60ths/second" );
}
EndUpdate(window);
}